package controller.data.readDocumentation;

import java.util.List;

import config.Parser;
import controller.data.Comment;
import controller.data.ReadDocumentationRevision;

public class ReadDocumentationResponse implements
		Comparable<ReadDocumentationResponse> {
	private String id;
	private ReadDocumentationRevision revision;
	private List<Comment> comments;
	private List<Long> ratings;
	private List<String> tags;

	public ReadDocumentationResponse(String id,
			ReadDocumentationRevision revision, List<Object> comments,
			List<Long> ratings, List<String> tags) {
		super();
		this.id = id;
		this.revision = revision;
		this.setTags(tags);
		setComments(comments);
	}

	public ReadDocumentationResponse() {
		// TODO Auto-generated constructor stub
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public ReadDocumentationRevision getRevision() {
		return revision;
	}

	public void setRevision(ReadDocumentationRevision revision) {
		this.revision = revision;
	}

	public List<Comment> getComments() {
		return comments;
	}

	public void setComments(List<Object> objects) {
		this.comments = new Parser().parseCommentList(objects);
	}

	public void setRatings(List<Long> ratings) {
		this.ratings = ratings;
	}

	public List<Long> getRatings() {
		return ratings;
	}

	public long getAverageRating() {
		long result = 0;
		for (long rating : ratings) {
			result += rating;
		}
		return ratings.size() > 0 ? result / ratings.size() : 0;
	}

	public int compareTo(ReadDocumentationResponse o) {
		return this.getRevision().getHeader()
				.compareTo(o.getRevision().getHeader());
	}

	public void setTags(List<String> tags) {
		this.tags = tags;
	}

	public List<String> getTags() {
		return tags;
	}
}
